package tp.pr4.gui;

import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.border.TitledBorder;
import javax.swing.JTextArea;
import java.awt.Cursor;

public class MapPanel extends JPanel
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private MapCell[][] _mapcellArray=new MapCell[11][11];
	private JPanel _mapa;
	private JTextArea _roomTextField;
	public MapPanel() {
		setLayout(new BorderLayout(0, 0));
		
		_roomTextField = new JTextArea();
		_roomTextField.setBorder(new TitledBorder(null, "Room", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		_roomTextField.setEditable(false);
		add(_roomTextField, BorderLayout.SOUTH);
		
		
		_mapa = new JPanel(new GridLayout(11, 11));
		_mapa.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		_mapa.setBorder(new TitledBorder(null, "Map", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		
		for (int i=0;i<11;i++){
            for (int j=0;j<11;j++) {
            	this._mapcellArray[i][j]=new MapCell(j,i,this._roomTextField);
                _mapa.add(this._mapcellArray[i][j]);
            }
        }
		
		add(_mapa, BorderLayout.CENTER);
	}
	public MapCell searchMapCell(int x, int y) {
		
		for (int i=0;i<11;i++){
         for (int j=0;j<11;j++) {
         	if (this._mapcellArray[i][j].get_x()==x && this._mapcellArray[i][j].get_y()==y)
         		return this._mapcellArray[i][j];
         }
     }
		return null;
	}
	
}